// JavaScript Document

$(document).ready(function(e) {
	
	
	var mainHeight=$(document).outerHeight();
	$('#right-detail,#side-menu').css('min-height',mainHeight-85);
	$('.flim-white').height(mainHeight);
	$('#hide-button').on('click',function(){
		if ($('#box-body').is(':visible')){
			$(this).html('<i class="fa fa-chevron-circle-down"></i>');
		}else{
			$(this).html('<i class="fa fa-chevron-circle-up"></i>');
		}
		
		$('#box-body').slideToggle();
	});
	$('.table-action > i').tooltip();
	
	$('#datetimepicker1,#datetimepicker2').datetimepicker({
        weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		minView: 2,
		forceParse: 0,
		orientation: 'top left',
		format:'yyyy-mm-dd'
	});
	
	$('#closeflim').on('click',function(){
		$('.flim-white').fadeOut();
	});
	
	$('#openflim').on('click',function(){
		$('.flim-white').fadeIn('slow',function(){
			var body = $("html, body");
			body.animate({scrollTop:0}, '500', 'swing', function() { 
			   
			});
		});
		
	});
	
	$('.change-bg').on('click',function(){
		var $id=$(this).attr('id');	
		
		$('.change-bg').each(function(index, element) {
			var $rid=$(this).attr('id');
			$('#right-detail').removeClass($rid);
			$('.form-wizard-box').removeClass($rid);
		});
		$('#right-detail').addClass($id);	
		$('.form-wizard-box').addClass($id);
	
	});
	
	$('.page-sidebar-menu > li > a').on('click',function(){
		var parent=$(this).parent();
		var $this=$(this);
		parent.next().children('a').addClass('add-border-top');
		//if (!$(this).hasClass('active')){
		if (!parent.hasClass('active')){
		$('.sub-menu').slideUp('fast',function(){			
				$(this).prev('a').removeClass('add-border-top');
				//$('.page-sidebar-menu > li > a').removeClass('active');
				$('.page-sidebar-menu > li').removeClass('active');
				$('.page-sidebar-menu > li > a >span').removeClass('open');
				//$(this).children('li').children('a').removeClass('active'); 
				$(this).children('li').removeClass('active'); 
				$(this).children('li').children('a').children('span.arrow').removeClass('open');
				$(this).children('li').children('.sub-menu').hide();		
		});
		}
		parent.children('ul').slideToggle('fast',function(){
			if (parent.children('ul').is(':visible')){
				//$this.addClass('active');
				parent.addClass('active');
				$this.children('span').addClass('open');
			}else{
				parent.next().children('a').removeClass('add-border-top');
				//$this.removeClass('active');
				
				parent.removeClass('active');
				$this.children('span').removeClass('open');
				parent.children('.sub-menu').hide();
				//parent.children('.sub-menu').children('li').children('a').removeClass('active'); 
				parent.children('.sub-menu').children('li').removeClass('active'); 
				parent.children('.sub-menu').children('li').children('a').children('span.arrow').removeClass('open');
				parent.children('.sub-menu').children('li').children('.sub-menu').hide();
			}
		});
	});
	
	$('.sub-menu > li > a').on('click',function(){
		var parent=$(this).parent();
		var $this=$(this);
		parent.children('ul').slideToggle('fast',function(){
			if (parent.children('ul').is(':visible')){
				//$this.addClass('active');
				parent.addClass('active');
				$this.children('span').addClass('open');
			}else{
				//$this.removeClass('active');
				parent.removeClass('active');
				$this.children('span').removeClass('open');
			}
		});
	});
	
	$('.step-link').on('click',function(){
		
		var boxID=$(this).data('link');
		$('.form-wizard-box').removeClass('active');
		$(this).children().addClass('active');
		$('.step-link').removeClass('active');
		$(this).addClass('active');
		$('.form-step').fadeOut('slow',function(){
			
			setTimeout(function(){
				
				$('#'+boxID).fadeIn('slow');
				
			},300);
			
		});
		
	});
	
});